﻿using System;
using System.Collections.Generic;
using PlaygroundSplines;
using UnityEngine;

namespace ParticlePlayground
{
	// Token: 0x02000168 RID: 360
	[Serializable]
	public class ManipulatorPropertyC
	{
		// Token: 0x0600088A RID: 2186 RVA: 0x00032B8C File Offset: 0x00030D8C
		public virtual void Update()
		{
			if (this.type == MANIPULATORPROPERTYTYPEC.Target)
			{
				for (int i = 0; i < this.targets.Count; i++)
				{
					this.targets[i].Update();
				}
			}
			else if (this.type == MANIPULATORPROPERTYTYPEC.MeshTarget)
			{
				if (this.meshTarget.gameObject != null)
				{
					if (this.meshTarget.cachedId != this.meshTarget.gameObject.GetInstanceID())
					{
						this.meshTarget = PlaygroundParticlesC.NewWorldObject(this.meshTarget.gameObject.transform);
					}
					if (this.meshTarget.mesh != null)
					{
						this.meshTargetMatrix.SetTRS(this.meshTarget.transform.position, this.meshTarget.transform.rotation, this.meshTarget.transform.localScale);
						if (this.meshTargetIsProcedural)
						{
							this.UpdateMeshTarget();
						}
					}
					if (this.meshTarget.initialized && (this.targetSortingList == null || this.targetSortingList.Length != this.meshTarget.vertexPositions.Length || this.previousTargetSorting != this.targetSorting))
					{
						this.TargetSorting();
					}
				}
			}
			else if (this.type == MANIPULATORPROPERTYTYPEC.SkinnedMeshTarget)
			{
				if (this.skinnedMeshTarget.gameObject != null)
				{
					if (this.skinnedMeshTarget.cachedId != this.skinnedMeshTarget.gameObject.GetInstanceID() || !this.skinnedMeshTarget.initialized)
					{
						this.skinnedMeshTarget = PlaygroundParticlesC.NewSkinnedWorldObject(this.skinnedMeshTarget.gameObject.transform);
					}
					if (this.skinnedMeshTarget.initialized)
					{
						if (this.meshTargetIsProcedural)
						{
							this.UpdateSkinnedMeshTarget();
						}
						this.skinnedMeshTarget.BoneUpdate();
						PlaygroundC.RunAsync(delegate()
						{
							this.skinnedMeshTarget.Update();
						});
						if (this.targetSortingList == null || this.targetSortingList.Length != this.skinnedMeshTarget.vertexPositions.Length || this.previousTargetSorting != this.targetSorting)
						{
							this.TargetSorting();
						}
					}
				}
			}
			else if (this.type == MANIPULATORPROPERTYTYPEC.StateTarget)
			{
				if (!this.stateTarget.initialized && (this.stateTarget.stateMesh != null || this.stateTarget.stateTexture != null) && this.stateTarget.stateTransform != null)
				{
					this.stateTarget.Initialize();
				}
				else if (this.stateTarget.initialized && this.stateTarget.stateTransform != null)
				{
					this.stateTarget.stateTransformMx.SetTRS(this.stateTarget.stateTransform.position, this.stateTarget.stateTransform.rotation, this.stateTarget.stateTransform.localScale);
				}
				if (this.stateTarget.initialized && (this.targetSortingList == null || this.targetSortingList.Length != this.stateTarget.positionLength || this.previousTargetSorting != this.targetSorting))
				{
					this.TargetSorting();
				}
			}
			else if (this.type == MANIPULATORPROPERTYTYPEC.SplineTarget)
			{
				this.splineTargetIsReady = (this.splineTarget != null && this.splineTarget.IsReady());
			}
			else if (this.type == MANIPULATORPROPERTYTYPEC.Turbulence)
			{
				if (this.turbulenceSimplex == null)
				{
					this.turbulenceSimplex = new SimplexNoise();
				}
			}
			else if (this.type == MANIPULATORPROPERTYTYPEC.Math)
			{
			}
		}

		// Token: 0x0600088B RID: 2187 RVA: 0x00032F68 File Offset: 0x00031168
		public virtual void UpdateMathProperty(Vector3 manipulatorPosition)
		{
			if (this.mathProperty == null)
			{
				this.mathProperty = new MathManipulatorProperty();
			}
			this.mathProperty.Update(manipulatorPosition);
		}

		// Token: 0x0600088C RID: 2188 RVA: 0x00032F8C File Offset: 0x0003118C
		public virtual void UpdateMeshTarget()
		{
			this.meshTarget.Update();
		}

		// Token: 0x0600088D RID: 2189 RVA: 0x00032F9C File Offset: 0x0003119C
		public virtual void UpdateSkinnedMeshTarget()
		{
			this.skinnedMeshTarget.Update();
		}

		// Token: 0x0600088E RID: 2190 RVA: 0x00032FAC File Offset: 0x000311AC
		public virtual void SetMeshTarget(GameObject gameObject)
		{
			this.meshTarget.gameObject = gameObject;
		}

		// Token: 0x0600088F RID: 2191 RVA: 0x00032FBC File Offset: 0x000311BC
		public virtual void SetSkinnedMeshTarget(GameObject gameObject)
		{
			this.skinnedMeshTarget.gameObject = gameObject;
		}

		// Token: 0x06000890 RID: 2192 RVA: 0x00032FCC File Offset: 0x000311CC
		public virtual bool SplineTargetIsReady()
		{
			return this.splineTargetIsReady;
		}

		// Token: 0x06000891 RID: 2193 RVA: 0x00032FD4 File Offset: 0x000311D4
		public virtual void TargetSorting()
		{
			if ((this.type == MANIPULATORPROPERTYTYPEC.MeshTarget && !this.meshTarget.initialized) || (this.type == MANIPULATORPROPERTYTYPEC.SkinnedMeshTarget && !this.skinnedMeshTarget.initialized) || (this.type == MANIPULATORPROPERTYTYPEC.StateTarget && !this.stateTarget.initialized))
			{
				return;
			}
			this.targetPointer = 0;
			if (this.type == MANIPULATORPROPERTYTYPEC.MeshTarget)
			{
				this.targetSortingList = new int[this.meshTarget.vertexPositions.Length];
			}
			else if (this.type == MANIPULATORPROPERTYTYPEC.SkinnedMeshTarget)
			{
				this.targetSortingList = new int[this.skinnedMeshTarget.vertexPositions.Length];
			}
			else if (this.type == MANIPULATORPROPERTYTYPEC.StateTarget)
			{
				this.targetSortingList = new int[this.stateTarget.positionLength];
			}
			switch (this.targetSorting)
			{
			case TARGETSORTINGC.Scrambled:
				for (int i = 0; i < this.targetSortingList.Length; i++)
				{
					this.targetSortingList[i] = i;
				}
				PlaygroundC.ShuffleArray(this.targetSortingList);
				break;
			case TARGETSORTINGC.Linear:
				for (int j = 0; j < this.targetSortingList.Length; j++)
				{
					this.targetSortingList[j] = j;
				}
				break;
			case TARGETSORTINGC.Reversed:
			{
				int num = 0;
				for (int k = this.targetSortingList.Length - 1; k > 0; k--)
				{
					this.targetSortingList[num] = k;
					num++;
				}
				break;
			}
			}
			this.previousTargetSorting = this.targetSorting;
		}

		// Token: 0x06000892 RID: 2194 RVA: 0x0003316C File Offset: 0x0003136C
		public virtual void SetLocalVelocity(Quaternion rotation, Vector3 newVelocity)
		{
			this.localVelocity = rotation * newVelocity;
		}

		// Token: 0x06000893 RID: 2195 RVA: 0x0003317C File Offset: 0x0003137C
		public virtual void SetLocalTargetsPosition(Transform otherTransform)
		{
			for (int i = 0; i < this.targets.Count; i++)
			{
				this.targets[i].SetLocalPosition(otherTransform);
			}
		}

		// Token: 0x06000894 RID: 2196 RVA: 0x000331B8 File Offset: 0x000313B8
		public virtual bool UpdateTarget(int index)
		{
			if (this.targets.Count > 0)
			{
				index %= this.targets.Count;
				this.targets[index].Update();
			}
			return this.targets[index].available;
		}

		// Token: 0x06000895 RID: 2197 RVA: 0x00033208 File Offset: 0x00031408
		public virtual ManipulatorPropertyC Clone()
		{
			ManipulatorPropertyC manipulatorPropertyC = new ManipulatorPropertyC();
			manipulatorPropertyC.type = this.type;
			manipulatorPropertyC.transition = this.transition;
			manipulatorPropertyC.velocity = this.velocity;
			manipulatorPropertyC.color = this.color;
			manipulatorPropertyC.lifetimeColor = this.lifetimeColor;
			manipulatorPropertyC.size = this.size;
			manipulatorPropertyC.useLocalRotation = this.useLocalRotation;
			manipulatorPropertyC.onlyColorInRange = this.onlyColorInRange;
			manipulatorPropertyC.keepColorAlphas = this.keepColorAlphas;
			manipulatorPropertyC.onlyPositionInRange = this.onlyPositionInRange;
			manipulatorPropertyC.zeroVelocityStrength = this.zeroVelocityStrength;
			manipulatorPropertyC.strength = this.strength;
			manipulatorPropertyC.targetPointer = this.targetPointer;
			manipulatorPropertyC.targets = new List<PlaygroundTransformC>();
			for (int i = 0; i < this.targets.Count; i++)
			{
				manipulatorPropertyC.targets.Add(this.targets[i].Clone());
			}
			manipulatorPropertyC.meshTarget = this.meshTarget.Clone();
			manipulatorPropertyC.skinnedMeshTarget = this.skinnedMeshTarget.Clone();
			manipulatorPropertyC.stateTarget = this.stateTarget.Clone();
			manipulatorPropertyC.turbulenceType = this.turbulenceType;
			manipulatorPropertyC.turbulenceApplyLifetimeStrength = this.turbulenceApplyLifetimeStrength;
			manipulatorPropertyC.turbulenceScale = this.turbulenceScale;
			manipulatorPropertyC.turbulenceTimeScale = this.turbulenceTimeScale;
			manipulatorPropertyC.turbulenceLifetimeStrength = new AnimationCurve(this.turbulenceLifetimeStrength.keys);
			return manipulatorPropertyC;
		}

		// Token: 0x04000895 RID: 2197
		public MANIPULATORPROPERTYTYPEC type;

		// Token: 0x04000896 RID: 2198
		public MANIPULATORPROPERTYTRANSITIONC transition;

		// Token: 0x04000897 RID: 2199
		public MathManipulatorProperty mathProperty = new MathManipulatorProperty();

		// Token: 0x04000898 RID: 2200
		public Vector3 velocity;

		// Token: 0x04000899 RID: 2201
		public Vector3 localVelocity;

		// Token: 0x0400089A RID: 2202
		public Color color = new Color(1f, 1f, 1f, 1f);

		// Token: 0x0400089B RID: 2203
		public Gradient lifetimeColor;

		// Token: 0x0400089C RID: 2204
		public float size = 1f;

		// Token: 0x0400089D RID: 2205
		public List<PlaygroundTransformC> targets = new List<PlaygroundTransformC>();

		// Token: 0x0400089E RID: 2206
		public int targetPointer;

		// Token: 0x0400089F RID: 2207
		public WorldObject meshTarget = new WorldObject();

		// Token: 0x040008A0 RID: 2208
		public SkinnedWorldObject skinnedMeshTarget = new SkinnedWorldObject();

		// Token: 0x040008A1 RID: 2209
		public bool meshTargetIsProcedural;

		// Token: 0x040008A2 RID: 2210
		public Matrix4x4 meshTargetMatrix = default(Matrix4x4);

		// Token: 0x040008A3 RID: 2211
		public ParticleStateC stateTarget = new ParticleStateC();

		// Token: 0x040008A4 RID: 2212
		public PlaygroundSplines.PlaygroundSpline splineTarget;

		// Token: 0x040008A5 RID: 2213
		public SPLINETARGETMETHOD splineTargetMethod;

		// Token: 0x040008A6 RID: 2214
		public float splineTimeOffset;

		// Token: 0x040008A7 RID: 2215
		protected bool splineTargetIsReady;

		// Token: 0x040008A8 RID: 2216
		public bool useLocalRotation;

		// Token: 0x040008A9 RID: 2217
		public bool onlyColorInRange = true;

		// Token: 0x040008AA RID: 2218
		public bool keepColorAlphas = true;

		// Token: 0x040008AB RID: 2219
		public bool onlyPositionInRange = true;

		// Token: 0x040008AC RID: 2220
		public bool onlySizeInRange;

		// Token: 0x040008AD RID: 2221
		public float zeroVelocityStrength = 1f;

		// Token: 0x040008AE RID: 2222
		public float strength = 1f;

		// Token: 0x040008AF RID: 2223
		public bool unfolded = true;

		// Token: 0x040008B0 RID: 2224
		public TARGETSORTINGC targetSorting;

		// Token: 0x040008B1 RID: 2225
		[NonSerialized]
		public int[] targetSortingList;

		// Token: 0x040008B2 RID: 2226
		protected TARGETSORTINGC previousTargetSorting;

		// Token: 0x040008B3 RID: 2227
		public TURBULENCETYPE turbulenceType = TURBULENCETYPE.Simplex;

		// Token: 0x040008B4 RID: 2228
		public float turbulenceTimeScale = 1f;

		// Token: 0x040008B5 RID: 2229
		public float turbulenceScale = 1f;

		// Token: 0x040008B6 RID: 2230
		public bool turbulenceApplyLifetimeStrength;

		// Token: 0x040008B7 RID: 2231
		public AnimationCurve turbulenceLifetimeStrength;

		// Token: 0x040008B8 RID: 2232
		public SimplexNoise turbulenceSimplex;
	}
}
